from typing import TYPE_CHECKING

from common.equipment.reference import Equipment

if TYPE_CHECKING:
    from common.player.reference import Player


class Weapon(Equipment):
    def __init__(self, key, **kwargs):
        super().__init__(key, **kwargs)

        self.attrs.update({
            'attack': kwargs['attack'],
            'penetrate': kwargs['penetrate'],
        })

    def dialog_content(self):
        rows = super().dialog_content()
        rows.insert(8, ('攻击力', self.attrs['attack']))
        rows.insert(9, ('穿透', self.attrs['penetrate']))
        return rows

    def install(self, player: 'Player'):
        old_equip = player.equip_slots.get('weapon')
        player.equip_slots['weapon'] = self
        player.bag.equipment.discard(self)
        if old_equip is not None:
            player.bag.cap.current += 1
            player.bag.equipment.add(old_equip)

        super().install(player)

    def uninstall(self, player: 'Player'):
        player.bag.equipment.add(self)
        player.equip_slots['weapon'] = None

        super().uninstall(player)
